<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>ES5的类</h1>
    <p>ES5里面使用构造函数来创建类。</p>
    <p>推荐语法：构造函数采用大驼峰命名规则。</p>
    <script>
        // 使用x和y坐标，创建一个点
        function Point(x,y) {
            this.x = x;
            this.y = y;

            // 求当前点与other点之间的距离
            this.distance = function(other) {
                let r = Math.pow(this.x - other.x,2) + Math.pow(this.y - other.y,2);
                return Math.pow(r,0.5);
            }
        }

        // prototype表示类的原型链，在类的原型链上挂载属性，那么类的所有对象都可以使用该属性。
        Point.prototype.show = function() {
            console.log("x = ",this.x,",y = ",this.y);
        }

        let point1 = new Point(50,50);

        let point2 = new Point(100,100);

        console.log(point1.distance(point2));
        point1.show();
        point2.show();

    </script>
</body>
</html>